<extend name="default/public/common" />

<block name="main">
    <div class="container" style="margin:50px auto;">
        <div class="row">
            <form class="form-horizontal">
                <div class="form-group">
                    <label for="exampleInputAccount7" class="col-lg-1">标题</label>
                    <div class="col-md-6 col-lg-11">
                        <input type="text" name="title" class="form-control" id="exampleInputAccount7" placeholder="请输入标题">
                    </div>
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword4" class="col-lg-1 required">类型</label>
                    <div class="col-md-6 col-lg-11">
                        <select class="form-control" name="section_id" id="exampleInputAddress1">
                            <volist name="titles" id="vo">
                            <option value="{$vo.id}">{$vo.title}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="exampleInputAccount9" class="col-lg-1 required">作者</label>
                    <div class="col-md-6 col-lg-11">
                        <select class="form-control" name="user_id" id="exampleInputAddress2">
                                <option value="{$user?$user['id']:'0'}">{$user?$user['username']:'游客'}</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="exampleInputAccount9" class="col-lg-1 required">内容</label>
                    <div class="col-md-6 col-lg-11">
                        <textarea id="editor" placeholder="" autofocus></textarea>
                        <script>
                            var editor = new Simditor({
                                textarea: $('#editor')
                            });
                        </script>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-lg-offset-1 col-lg-11">
                        <a  class="btn btn-primary" href="javascript:" onclick="onSub();">提交</a>
                    </div>
                </div>
            </form>
            <script>
            function onSub() {
            // 帐号
            var title = $('input[name=title]').val();
            var section_id = $('select[name=section_id] option:selected').val();
            var user_id=$('select[name=user_id] option:selected').val();
            var content=editor.getValue();
            $.ajax({
            type: "POST",
            url: '{:U("bbs/baocun")}',
            dataType: 'json',
            cache: false,
            data: {title: title, section_id: section_id, user_id:user_id,content:content},
            success: function(data) {
            location.href = "{:U('bbs/index')}";
            },
            error: function(xhr, status, error) {
            console.log(xhr);
            console.log(status);
            console.log(error);
            }
            });
            }

            </script>
        </div>
    </div>
</block>